package com.kc.web.controller.business;

import com.kc.business.domain.BizScenicSiteVideo;
import com.kc.business.service.IBizScenicSiteVideoService;
import com.kc.common.annotation.Log;
import com.kc.common.annotation.RepeatSubmit;
import com.kc.common.core.controller.BaseController;
import com.kc.common.core.domain.AjaxResult;
import com.kc.common.core.page.TableDataInfo;
import com.kc.common.enums.BusinessType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 景点视频Controller
 */
@RestController
@RequestMapping("/business/siteVideo")
public class BizSiteVideoController extends BaseController {
    @Autowired
    private IBizScenicSiteVideoService siteVideoService;
    /**
     * 景点视频列表
     * @param bizScenicSiteVideo
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:siteVideo:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizScenicSiteVideo bizScenicSiteVideo) {
        startPage();
        List<BizScenicSiteVideo> list = siteVideoService.getList(bizScenicSiteVideo);
        return getDataTable(list);
    }

    /**
     * 新增视频
     */
    @PreAuthorize("@ss.hasPermi('business:siteVideo:add')")
    @Log(title = "景点视频管理", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@Validated @RequestBody BizScenicSiteVideo bizScenicSiteVideo) {
        if(bizScenicSiteVideo.getUserId() == null){
            bizScenicSiteVideo.setUserId(0);
        }
        return toAjax(siteVideoService.add(bizScenicSiteVideo));
    }
    /**
     * 修改视频
     */
    @PreAuthorize("@ss.hasPermi('business:siteVideo:edit')")
    @Log(title = "景点视频管理", businessType = BusinessType.UPDATE)
    @PutMapping
    @RepeatSubmit
    public AjaxResult edit(@Validated @RequestBody BizScenicSiteVideo bizScenicSiteVideo) {
        return toAjax(siteVideoService.edit(bizScenicSiteVideo));
    }

    /**
     * 删除视频
     */
    @PreAuthorize("@ss.hasPermi('business:siteVideo:remove')")
    @Log(title = "景点视频管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Integer id) {
        BizScenicSiteVideo scenicSiteVideo = new BizScenicSiteVideo();
        scenicSiteVideo.setId(id);
        scenicSiteVideo.setIsDeleted(1);
        return toAjax(siteVideoService.edit(scenicSiteVideo));
    }

}
